// 관리자 포털
var statusList = new Array(2);
// 작업 상태(job)
// 0:Progress, 1:Queuing, 2:Cancel, 3:Failure, 4:Success 
statusList[0] = new Array();
statusList[0][0] = "/icon/progress.gif";
statusList[0][1] = "/icon/queuing.gif";
statusList[0][2] = "/icon/cancel.gif";
statusList[0][3] = "/icon/failure.gif";
statusList[0][4] = "/icon/success.gif";
// 경고 레벨(level)
// 0:정상, 1:경고, 2:위험, 3:정보 확인 불가
statusList[1] = new Array();
statusList[1][0] = "/icon/00.gif";
statusList[1][1] = "/icon/01.gif";
statusList[1][2] = "/icon/02.gif";
statusList[1][3] = "/icon/09.gif";
// 연결 상태(connect)
// 0:장애, 1:정상
statusList[2] = new Array();
statusList[2][0] = "/icon/02.gif";
statusList[2][1] = "/icon/00.gif";
// 전원 상태(power)
//0:UP, 1:DOWN, 2:SUSPEND
statusList[3] = new Array();
statusList[3][0] = "/icon/up.gif";
statusList[3][1] = "/icon/down.gif";
statusList[3][2] = "/icon/suspend.gif";
// 처리 상태(result)
// 0:정상, 1:장애
statusList[4] = new Array();
statusList[4][0] = "/icon/00.gif";
statusList[4][1] = "/icon/02.gif";
// 사용 상태(result)
// Y:사용, N:사용안함
statusList[5] = new Array();
statusList[5][0] = "/btn/on.gif";
statusList[5][1] = "/btn/off.gif";
// 스위치 상태(result)
// 0:OFF, 1:ON
statusList[6] = new Array();
statusList[6][0] = "/icon/off.gif";
statusList[6][1] = "/icon/on.gif";

// 대쉬보드
var dashStatusList = new Array(2);
dashStatusList[0] = "";
// 경고 레벨(level)
// 0:정상, 1:경고, 2:위험, 3:정보 확인 불가
dashStatusList[1] = new Array();
dashStatusList[1][0] = "/board/list_icon1.gif";
dashStatusList[1][1] = "/board/list_icon3.gif";
dashStatusList[1][2] = "/board/list_icon2.gif";
dashStatusList[1][3] = "/board/list_icon9.gif";
// 연결 상태(connect)
// 0:장애, 1:정상
dashStatusList[2] = new Array();
dashStatusList[2][0] = "/board/list_icon2.gif";
dashStatusList[2][1] = "/board/list_icon1.gif";

// 클래스
var statusClassList = new Array(2);
statusClassList[0] = "";
// 경고 레벨(level)
// 0:정상, 1:경고, 2:위험, 3:정보 확인 불가
statusClassList[1] = new Array();
statusClassList[1][0] = "";
statusClassList[1][1] = "color_err1";
statusClassList[1][2] = "color_err2";
statusClassList[1][3] = "";
// 연결 상태(connect)
// 0:장애, 1:정상
statusClassList[2] = new Array();
statusClassList[2][0] = "icon3";
statusClassList[2][1] = "icon2";

/**
 * 입력된 변수에 따른 상태 이미지를 출력한다.
 * 
 * @param action :: 리스트 선택 (portal:관리자 포털, dash:대쉬보드)
 * @param target :: 타겟 아이디
 * @param job :: 상태 구분
 * @param status :: 상태값
 * @param desc :: 상태 설명
 * @param imgSrc :: 이미지 부모 경로
 */
function printStatus(action, target, job, status, desc, imgSrc) {
	var arg0 = 0;
	var arg1 = 0;

	if (job == "job") {
		arg0 = 0;
		if (status == "progress") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Progress (" + desc + ")" : "Progress";
		} else if (status == "queuing") {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Queuing (" + desc + ")" : "Queuing";
		} else if (status == "cancel") {
			arg1 = 2;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Cancel (" + desc + ")" : "Cancel";
		} else if (status == "failure") {
			arg1 = 3;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Failure (" + desc + ")" : "Failure";
		} else if (status == "success") {
			arg1 = 4;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Success (" + desc + ")" : "Success";
		}
	} else if (job == "level") {
		arg0 = 1;
		if (status == "0") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "정상 (" + desc + ")" : "정상";
		} else if (status == "1") {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "경고 (" + desc + ")" : "경고";
		} else if (status == "2" || status == "3") {
			arg1 = 2;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "위험 (" + desc + ")" : "위험";
		} else {
			arg1 = 3;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "정보 확인 불가 (" + desc + ")" : "정보 확인 불가";
		}
	} else if (job == "connect") {
		arg0 = 2;
		if (status == "1" || status == "2" || status == "9") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "장애 (" + desc + ")" : "장애";
		} else {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "정상 (" + desc + ")" : "정상";
		}
	} else if (job == "power") {
		arg0 = 3;
		if (status == "0") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Up (" + desc + ")" : "Up";
		} else if (status == "2") {
			arg1 = 2;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Suspend (" + desc + ")" : "Suspend";
		} else {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "Down (" + desc + ")" : "Down";
		}
	} else if (job == "result") {
		arg0 = 4;
		if (status == "0") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "정상 (" + desc + ")" : "정상";
		} else {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "장애 (" + desc + ")" : "장애";
		}
	} else if (job == "use") {
		arg0 = 5;
		if (status == "Y") {
			arg1 = 0;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "사용 (" + desc + ")" : "사용";
		} else {
			arg1 = 1;
			desc = (desc != null  & desc != ""  & desc != "undefined") ? "사용안함 (" + desc + ")" : "사용안함";
		}
	} else if (job == "value") {
		arg0 = 6;
		if (status == "2") {
			desc = "<img src='" + imgSrc + "/" + statusList[arg0][desc] + "'/>";
		}
	}

//	alert("arg0 :: " + arg0 + "\narg1 :: " + arg1 + "\nstatusList :: " + statusList[arg0][arg1]);
	if (action == "class") {
		$("#" + target).addClass(statusClassList[arg0][arg1]);
	} else if (action == "text") {
		$("#" + target).html(desc);
	} else if (action == "dash") {
		$("#" + target).html("<img src='" + imgSrc + "/" + dashStatusList[arg0][arg1] + "' title='" + desc + "'/>");
	} else {
		$("#" + target).html("<img src='" + imgSrc + "/" + statusList[arg0][arg1] + "' title='" + desc + "'/>");
	}
}

function parseProcessMsg(msg) {
	alert(msg.indexof("Process"));
}

// 13241건 [경고(11350건), 위험(1891건)] Go...
// Change 정상 2건 경고 0건 위험 0건 Go...
function printSumary(action, target, job, 
		sumVal, sumUnit, 
		pos0Desc, pos0Val, pos0Unit, 
		pos1Desc, pos1Val, pos1Unit, 
		pos2Desc, pos2Val, pos2Unit, 
		imgSrc, titleDesc) {

	//	alert("action :: " + action + "\ntarget :: " + target + "\njob :: " + job + "\nsumVal :: " + sumVal + "\nsumUnit :: " + sumUnit + "\npos0Desc :: " + pos0Desc + "\npos0Val :: " + pos0Val + "\npos0Unit :: " + pos0Unit + "\npos1Desc :: " + pos1Desc + "\npos1Val :: " + pos1Val + "\npos1Unit :: " + pos1Unit + "\npos2Desc :: " + pos2Desc + "\npos2Val :: " + pos2Val + "\npos2Unit :: " + pos2Unit + "\nimgSrc :: " + imgSrc + "\ntitleDesc ::" + titleDesc);
	
	var classStyleError = "val_style_error";
	var classStyleWarn = "val_style_warn";
	var classStyleNormal = "val_style_normal";
	
	var desc = "";
	var classStyle = classStyleNormal;
	// sumVal
	if (false && sumVal != null) {
		if (sumVal>0) desc+="<b>"+sumVal+"</b>";
		else desc+=""+sumVal+"";
		desc += sumUnit + "&nbsp;" + "[";
	}
	// pos1Val
	if (pos0Val>0) classStyle = classStyleNormal;
	else classStyle = classStyleNormal;
	if (pos0Desc!=null&&pos0Desc!="") desc +=""+pos0Desc+" <span class="+classStyle+">"+pos0Val+"</span>"+pos0Unit+", ";
		
	// pos1Val
	if (pos1Val>0) classStyle = classStyleWarn;
	else classStyle = classStyleNormal;
	desc +=""+pos1Desc+" <span class="+classStyle+">"+pos1Val+"</span>"+pos1Unit+", ";
	
	// pos2Val
	if (pos2Val>0) classStyle = classStyleError;
	else classStyle = classStyleNormal;
	desc +=""+pos2Desc+" <span class="+classStyle+">"+pos2Val+"</span>"+pos2Unit+"";
	
	if (false && sumVal != null) {
		desc += "]";
	}
	
	var imgGo = "Go..";
	if (imgSrc != null && imgSrc != "") imgGo = "<img src='" + imgSrc + "' title='" + titleDesc + "'/>";
	
	classStyle = classStyleNormal;
	if (pos1Val>0) classStyle = classStyleWarn;
	if (pos2Val>0) classStyle = classStyleError;
	if ((pos1Val>0) || (pos2Val>0)) {
		desc +="&nbsp;"+"<span class="+classStyle+"><a href='"+action+"' title=''>"+imgGo+"</a></span>";
	} else {
		desc +="&nbsp;"+"<span class="+classStyle+"><a href='"+action+"' title=''>"+imgGo+"</a></span>";
	}
	//alert("set "+target+", Text="+desc);
	$("#" + target).html(desc);
}

function printSumary_old(action, target, job, 
			sumVal, sumUnit, 
			pos1Desc, pos1Val, pos1Unit, 
			pos2Desc, pos2Val, pos2Unit, 
			imgSrc, titleDesc) {

	//	alert("action :: " + action + "\ntarget :: " + target + "\njob :: " + job + "\nsumVal :: " + sumVal + "\nsumUnit :: " + sumUnit + "\npos1Desc :: " + pos1Desc + "\npos1Val :: " + pos1Val + "\npos1Unit :: " + pos1Unit + "\npos2Desc :: " + pos2Desc + "\npos2Val :: " + pos2Val + "\npos2Unit :: " + pos2Unit + "\nimgSrc :: " + imgSrc + "\ntitleDesc ::" + titleDesc);
	
	var classStyleError = "val_style_error";
	var classStyleWarn = "val_style_warn";
	var classStyleNormal = "val_style_normal";
	
	var desc = "";
	var classStyle = classStyleNormal;
	// sumVal
	if (sumVal != null) {
		if (sumVal>0) desc+="<b>"+sumVal+"</b>";
		else desc+=""+sumVal+"";
		desc += sumUnit + "&nbsp;" + "[";
	}
	// pos1Val
	if (pos1Val>0) classStyle = classStyleWarn;
	else classStyle = classStyleNormal;
	desc +=""+pos1Desc+"(<span class="+classStyle+">"+pos1Val+"</span>"+pos1Unit+"), ";
	
	// pos2Val
	if (pos2Val>0) classStyle = classStyleError;
	else classStyle = classStyleNormal;
	desc +=""+pos2Desc+"(<span class="+classStyle+">"+pos2Val+"</span>"+pos2Unit+")";

	if (sumVal != null) {
		desc += "]";
	}

	var imgGo = "Go..";
	if (imgSrc != null && imgSrc != "") imgGo = "<img src='" + imgSrc + "' title='" + titleDesc + "'/>";
	
	classStyle = classStyleNormal;
	if (pos1Val>0) classStyle = classStyleWarn;
	if (pos2Val>0) classStyle = classStyleError;
	if ((pos1Val>0) || (pos2Val>0)) {
		desc +="&nbsp;"+"<span class="+classStyle+"><a href='"+action+"' title=''>"+imgGo+"</a></span>";
	}
	//alert("set "+target+", Text="+desc);
	$("#" + target).html(desc);
}

var chartMaxLabel = 10; // 차트 표현 최대 수